package com.shut.vehicle.interceptor.token;

import com.shut.vehicle.pojo.User;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 卢斌
 */
@Slf4j
public class UserThread {

    private static final ThreadLocal<User> threadStorage = new ThreadLocal<>();


    /**
     * 当前线程容器保存用户信息
     */
    public static void setUserInfo(User userEnt) {
        threadStorage.set(userEnt);
    }

    /**
     * 线程容器中获取发出请求的用户的Id
     */
    public static Integer userId() {
        User userEnt = threadStorage.get();
        if (userEnt == null) {
            return null;
        }
        return threadStorage.get().getId();
    }


    /**
     * 清理线程容器资源
     */
    public static void cleanLocalVar() {
        threadStorage.remove();
    }

}
